<?php
include "soar/web.inc";

function main()
{/*{{{*/
    if(isset($_POST['input_code']))
    {/*{{{*/
        $svcenv=new svcenv();
        $confirm=$svcenv->confirm();

        $code=$_POST['input_code'];
        $token=$_COOKIE['confirm_token'];
        $res=$confirm->submit($token, $code);
        echo <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
EOD;
        if($res == false)
        {
            echo "验证失败，转回<a href=\"confirm.php\">验证页面</a>".
                "<br/>\n";
        }
        else
        {
            echo "验证成功<br/>\n";
        }
        echo <<<EOD
</body>
</html>
EOD;

        $svcenv->close();
    }/*}}}*/
    else
    {/*{{{*/
        echo <<<EOD
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<script type="text/javascript">
function change_img_confirm()
{
    document.getElementById("img_confirm").src="confirm_generate.php?"+Math.random();
}

function validate()
{
    code=document.form_submit.input_code.value;
    if(code.length != 4)
    {
        alert("验证码错误！");
        document.form_submit.input_code.focus();
        return false;
    }
    return true;
}
</script>
</head>
<body>
<form id="form_submit" name="form_submit" method="post" onsubmit="return validate()" action="confirm_submit.php">
<table width="300" border="1" cellpadding="0" cellspacing="0">
<tr>
    <td align="left">
        <input name="input_code" id="input_code" type="textbox" class="inputbox" size="20"/>&nbsp;
        <img id="img_confirm" style="margin-top:2px;cursor:pointer" src="confirm_generate.php" width="80" height="30" align="absmiddle" onclick="JavaScript:change_img_confirm()" title="我看不清"/>
    </td>
</tr>
<tr>
    <td><input type="submit" name="submit" value="提交"></td>
</tr>
</table>
</form>
</body>
</html>
EOD;
    }/*}}}*/
}/*}}}*/

main();
?>
